package com.wrupple.muba.catalogs.client.activity.process.impl;

import java.util.List;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Widget;
import com.wrupple.muba.catalogs.client.activity.process.LoadSelectionProcessData;
import com.wrupple.muba.catalogs.client.activity.process.SelectionProcess;
import com.wrupple.muba.catalogs.client.activity.process.task.SelectionState;
import com.wrupple.muba.catalogs.client.view.DataView;
import com.wrupple.muba.catalogs.domain.CatalogProcessDescriptor;
import com.wrupple.muba.common.shared.SequentialProcess;
import com.wrupple.muba.common.shared.StateTransition;

public class SimpleSelectionProcess<O> extends
		SequentialProcess<CatalogProcessDescriptor, List<O>> implements
		SelectionProcess<O> {

	SelectionState<O> entrySelection;

	public SimpleSelectionProcess(
			LoadSelectionProcessData loadEntryTypes,
			SelectionState<O> entrySelection) {
		super();
		this.entrySelection = entrySelection;
		add(loadEntryTypes);
		add(entrySelection);
	}

	@Override
	public Widget asWidget() {
		return (Widget) context.getOutputFeature();
	}

	@Override
	public DataView<O> getBrowseView() {
		return entrySelection.getBrowseView();
	}

	public SelectionState<O> getEntrySelection() {
		return entrySelection;
	}

	public void setEntrySelection(SelectionState<O> entrySelection) {
		this.entrySelection = entrySelection;
	}

	@Override
	public void startSelection(StateTransition<List<O>> callback) {
		entrySelection.startSelection(callback);
	}

	public void setAction(List<? extends HasClickHandlers> actions) {
		entrySelection.getBrowseView().setAction(actions);
	}

}
